import axios from "axios";
import { ElMessage } from "element-plus";

const service = axios.create({
  baseURL: "http://yert.top:8899",
  timeout: 10000,
});

service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    Promise.reject(error);
  }
);

service.interceptors.response.use(
  (res) => {
    const code = res.data.code;
    const msg = res.data.msg;
    if (code === 500) {
      ElMessage({
        message: msg,
        type: "error",
      });
      return Promise.reject(new Error(msg));
    } else {
      return res.data;
    }
  },
  (error) => {
    return Promise.reject(error);
  }
);

export default service;
